home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / tvx.arc / TVX-CFG.C < prev    next >
C/C++ Source or Header  |  1989-07-30  |  17KB  |  629 lines

  1. /* ------------------------------- tvx_cfg.c ------------------------ */
  2. #include "tvx_defs.ic"
  3.  
  4. #define BL remark("")
  5.  
  6.     char synofr[20] =    /* from table */
  7.       {' ',13,']',000,000,000,000,000,000,000,00,00,00,00,00,00,00,00,00,00};
  8.     char synoto[20] =        /* translate to table */
  9.       {'r','d','{',00,000,0,000,00,00,000,00,00,00,00,00,00,00,00,00,00};
  10.     char funkey = 0;        /* leading char for function key */
  11.     char funchar[50] =    /* code sent by function key */
  12.       {
  13.     000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
  14.     000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
  15.     000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
  16.     000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
  17.     000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
  18.       };
  19.     char funcmd[50] =    /* equivalent command */
  20.       {
  21.     000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
  22.     000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
  23.     000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
  24.     000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
  25.     000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
  26.       };
  27.  
  28. /* define standard command set */
  29.  
  30.     char lexsym[LEXVALUES+1] = { E0, 'r', 'l', 'd', 'u',
  31.       4, 21, 8, 'k', 'i', 11, '"', '\'', ',', '.', 'f', 6, 'p',
  32.       'b', 'e', 2, 'v', 'o', '/', 's', 'g', 23, 25, 24, ';', '&',
  33.       'm', ':', '=', 7, 9, '{', 'a', 16, '?', 'h', 20, 'c', 'j', 't',
  34.       'n', 14, 15, 5, 18, '#', '*', '(', ')' };
  35.  
  36.     char newlex[LEXVALUES+1] ;
  37.  
  38.     char autoin, dsplin, scroll, xcases, warplm, wildch, funesc;
  39.     char rp[80];
  40.  
  41.     FILE *f, *fopen();
  42.  
  43.   main()
  44.   {
  45.  
  46.     FAST int i, val;
  47.  
  48.     cls();
  49.     remark("TVX define a configuration file -- Version 11/12/85");
  50.     BL;
  51.     for (;;)
  52.       {
  53.     prompt("Enter name of file to save configuration in: ");
  54.     reply(rp,79);
  55.     if ((f = fopen(rp,FILEWRITE)) == 0)
  56.         continue;
  57.     else
  58.         break;
  59.       }
  60.  
  61.  
  62.     remark("Standard commands settable by this program:");
  63.  
  64.     BL;
  65. remark("Commands (n => count allowed):");
  66. remark("nA Append lines  B Buff begin   ^B File begin   nC Change chrs  nD Down");
  67. remark("n^D Down column  E Buff end     nF Find         ^F Find-file     G Get save buf");
  68. remark("^G Unkill       nH Half page    nI Insert        J Jump back    nK Kill ch");
  69. remark("n^K Kill line   nL Left          M Mem stat     nN Note loc     n^N Reset loc");
  70. remark("nO Open line    nP Page         ^P Print screen ^Q Quit         nR Right");
  71. remark("nS Save lines   ^S Read file    nT Tidy         ^T Abort        nU Up");
  72. remark("n^U Up column    V Verify      n^W Write buff   nBS Del ch      n; Re-Find");
  73. remark(" / Delete last   = Change last   ' Del ln beg     \" Del ln end   , Ln beg");
  74. remark(" . Line end     nTAB Word rt    n{ Word left    n& Rpt agn");
  75. remark("? Help           * Ins find pat n:p Set param p ^O Op. System");
  76. remark("n^E Edit rptbuf  ^R Restore rpt n#k Execute rpt n k times");
  77. remark("Note: <> repeat, @ command file, and ESCAPE cannot be changed.");
  78.     BL;
  79.  
  80.     for (;;)
  81.       {
  82.     BL;
  83.     prompt("Use standard command definitions? (y/n) ");
  84.     lreply(rp,10);
  85.     if (*rp == 'y')
  86.       {
  87.         for (i=0 ; i <= LEXVALUES ; ++i)
  88.         fputc(lexsym[i],f);        /* write to file */
  89.         goto LEXDONE;
  90.       }
  91.     else if (*rp == 'n')
  92.         break;
  93.       }
  94.  
  95. CAGAIN:
  96.     cls();
  97.     remark("You now must re-define all 47 commands.  You may simply enter");
  98.     remark("the key of the command (followed by a RETURN), or the decimal");
  99.     remark("code of the key, followed by a RETURN.");
  100.     BL;
  101. /* define new commands */
  102.     for (i=0 ; i <= LEXVALUES ; ++i)
  103.     newlex[i] = 0;        /* clear  */
  104.     set(1,"cursor right (r)");
  105.     set(2,"cursor left (l)");
  106.     set(3,"cursor down (d)");
  107.     set(4,"cursor up (u)");
  108.     set(5,"cursor down in col (^d)");
  109.     set(6,"cursor up in col (^u)");
  110.     set(7,"del prev char (backspace)");
  111.     set(8,"kill character (k)");
  112.     set(9,"enter insert mode (i)");
  113.     set(10,"kill a line (^k)");
  114.     set(11,"delete to end of line (\")");
  115.     set(12,"delete to beginning of line (')");
  116.     set(13,"cursor to beginning of line (,)");
  117.     set(14,"cursor to end of line (.)");
  118.     set(15,"find (f)");
  119.     set(16,"find across buffer (^f)");
  120.     set(17,"scroll screen one page (p)");
  121.     set(18,"beginning of buffer (b)");
  122.     set(19,"end of buffer (e)");
  123.     set(20,"beginning of file (^b)");
  124.     set(21,"verify screen (v)");
  125.     set(22,"open line (o)");
  126.     set(23,"delete last thing (/)");
  127.     set(24,"save line in save buff (s)");
  128.     set(25,"get save buffer (g)");
  129.     set(26,"write buffer (^w)");
  130.     set(27,"save external file in save buffer (^y)");
  131.     set(28,"exit (^x)");
  132.     set(29,"find again (;)");
  133.     set(30,"execute repeat buffer (&)");
  134.     set(31,"memory status line (m)");
  135.     set(32,"set parameter (:)");
  136.     set(33,"delete last thing, enter insert (=)");
  137.     set(34,"get back last killed line (^g)");
  138.     set(35,"word rigth (tab)");
  139.     set(36,"word left ({)");
  140.     set(37,"append line to save buffer (a)");
  141.     set(38,"print screen (^p)");
  142.     set(39,"help (?)");
  143.     set(40,"scroll page half screen (h)");
  144.     set(41,"abort edit session (^t)");
  145.     set(42,"change characters (c)");
  146.     set(43,"jump back (j)");
  147.     set(44,"tidy (fill to margin) (t)");
  148.     set(45,"note position (n)");
  149.     set(46,"return to noted position (^n)");
  150.     set(47,"'push' to operating system (^O)");
  151.     set(48,"Edit repeat buffer (^E)");
  152.     set(49,"Restore repeat buffer (^R)");
  153.     set(50,"Execute repeat buffer k (#)");
  154.     set(51,"Insert last find match (*)");
  155.  
  156.     cls();
  157. remark("Commands have been defined. You can start over if you made any mistakes.");
  158.     remark("");
  159.     prompt("Are they ok? (y/n) ");
  160.     lreply(rp,10);
  161.     if (*rp == 'n')
  162.     goto CAGAIN;
  163.     
  164.     for (i=0 ; i <= LEXVALUES ; ++i)
  165.       {
  166.     fputc(newlex[i],f);        /* write to file */
  167.     lexsym[i] = newlex[i];
  168.       }
  169.  
  170. LEXDONE:
  171.     syno();
  172.     funkeys();
  173.  
  174.     cls();
  175.     prompt("Use autoindent (n default) (y/n): ");
  176.     lreply(rp,10);
  177.     if (*rp == 'y')
  178.     fputc(1,f);
  179.     else 
  180.     fputc(0,f);
  181.  
  182.     BL;
  183.     prompt("Home display line: (1-66, 16 default): ");
  184.     rdint(&val);
  185.     if (val > 66 || val <= 0)
  186.     fputc(16,f);
  187.     else
  188.         fputc(val,f);
  189.  
  190.     BL;
  191.     prompt("Scroll window (0 default): ");
  192.     rdint(&val);
  193.     if (val > 24)
  194.     val = 0;
  195.     fputc(val,f);
  196.  
  197.     BL;
  198.     prompt("Find case (e=exact,a=any, any default): "); 
  199.     lreply(rp,10);
  200.     if (*rp == 'e')
  201.         fputc(1,f);
  202.     else
  203.         fputc(0,f);
  204.  
  205.     BL;
  206.  
  207.     prompt("Auto line wrap width (0 default): ");
  208.     rdint(&val);
  209.     if (val > 79)
  210.     val = 0;
  211.     fputc(val,f);
  212.  
  213.     BL;
  214.     prompt("Use wild cards (y default) (y/n)? ");
  215.     lreply(rp,10);
  216.     if (*rp == 'n')
  217.     fputc(0,f);
  218.     else 
  219.     fputc(1,f);
  220.  
  221.     BL;
  222.     prompt("Use BACKUP.LOG file (n default) (y/n)? ");
  223.     lreply(rp,10);
  224.     if (*rp == 'y')
  225.         fputc(1,f);
  226.     else
  227.         fputc(0,f);
  228.     
  229. #ifdef MSDOS
  230.     BL;
  231.     remark("The editor can recognize Ctrl-z as EOF, or it can ignore ^Z and");
  232.     remark("just use the standard MS-DOS end of file mark.");
  233.     prompt("Should the editor recognize Ctrl-Z as EOF? (y/n) ");
  234.     lreply(rp,10);
  235.     if (*rp == 'y')
  236.         fputc(1,f);
  237.     else
  238.         fputc(0,f);
  239. #endif
  240.  
  241.     cls();
  242.     remark("Configuration file created.");
  243.     fclose(f);
  244.   }
  245.  
  246. /* ===============================>>> FUNKEYS <<<========================*/
  247.   funkeys()
  248.   {
  249.  
  250.     FAST int j,i,val;
  251.     SLOW int fun;
  252.  
  253. FAGAIN:
  254.     cls();
  255.     remark("You may now define up to 49 function keys to be translated to");
  256.     remark("commands OR letters.  This translation will take place before");
  257.     remark("the editor gets the character at any level  -- thus the translation");
  258.     remark("will apply equally to command mode and insert mode.  The translation");
  259.     remark("assumes each function key generates a 2 character sequence.  The");
  260.     remark("first character is an 'escape' character that must be the same for");
  261.     remark("each key.  If the 'escape' character is really ESC, then you must");
  262.     remark("also define one function key to have ESC as its translation value.");
  263.     remark("When asked for the function key, simply press the key, followed by");
  264.     remark("RETURN.  Enter either the character or decimal value of the translation.");
  265.  
  266.     for (i = 0 ; i < 50 ; ++i)
  267.       {
  268.     funchar[i] = funcmd[i] = 0;
  269.       }
  270.  
  271.     BL;
  272.     prompt("Do you want to define any function keys? (y/n) ");
  273.     lreply(rp,10);
  274.     if (*rp == 'n')
  275.     goto WTFUN;
  276.  
  277.     BL;
  278.     remark("Now, please press ANY function key so the program can identify");
  279.     prompt("the 'function key escape' code (followed by a RETURN): ");
  280.     reply(rp,10);
  281.     funesc = *rp;        /* this should be the escape char */
  282.     if (funesc == 27)
  283.       {
  284.     BL;
  285.     remark("IMPORTANT:  You MUST define a function key to send an ESCAPE (decimal 27).");
  286.     remark("If you don't, then you won't be able to end insert mode or repeat loops.");
  287.     remark("The program doesn't have logic to make sure you do this, so don't forget!");
  288.     BL;
  289.       }
  290.  
  291.     for (i = 0 ; i < 50 ; ++i)
  292.       {
  293. FUNAGAIN:
  294.     prompt("Press function key to define (RETURN only to exit): ");
  295.      rp[1] = 0;
  296.     reply(rp,10);
  297.     fun = rp[1];
  298.     if (rp[1] == 0)
  299.         break;
  300.     for (j = 0 ; j < 50 ; ++j)
  301.       {
  302.         if (fun == funchar[j])
  303.           {
  304.         remark("That's been used already, try again.");
  305.         goto FUNAGAIN;
  306.           }
  307.       }
  308.     funchar[i] = fun;
  309.     prompt("Now enter the character/command it gets translated to: ");
  310.     reply(rp,10);
  311.     val = getval(rp);
  312.     funcmd[i] = val;
  313.       }
  314.  
  315.     cls();
  316. remark("Functions have been defined. You can start over if you made any mistakes.");
  317.     remark("");
  318.     prompt("Are they ok? (y/n) ");
  319.     lreply(rp,10);
  320.     if (*rp == 'n')
  321.     goto FAGAIN;
  322.  
  323. WTFUN:
  324.     for (i = 0 ; i < 50 ; ++i)
  325.       {
  326.     fputc(funchar[i],f);
  327.       }
  328.     for (i = 0 ; i < 50 ; ++i)
  329.       {
  330.     fputc(funcmd[i],f);
  331.       }
  332.     fputc(funesc,f);
  333.   }
  334.   
  335.  
  336. /* ===============================>>> GETVAL <<<========================*/
  337.   getval(str)
  338.   char *str;
  339.   {
  340.     /* return one byte value */
  341.  
  342.     if (*str >= '0' && *str <= '9')
  343.     return (atoi(str));
  344.     else
  345.     return (*str & 0377);
  346.   }
  347.  
  348. /* ===============================>>> SET <<<========================*/
  349.   set(indx,msg)
  350.   int indx;
  351.   char *msg;
  352.   {
  353.     /* set newlex[indx] to a new value */
  354.  
  355.     SLOW int val,i;
  356.  
  357. SAGAIN:
  358.     prompt("Enter new command for "); prompt(msg); prompt(": ");
  359.     reply(rp,10);
  360.     val = getval(rp);
  361.  
  362.     if (val == 0)
  363.       {
  364.     remark("Invalid value, try again");
  365.     goto SAGAIN;
  366.       }
  367.     for (i = 1 ; i <= LEXVALUES ; ++i)
  368.       {
  369.     if (val == newlex[i])
  370.       {
  371.         remark("That value has been already used.  Try again.");
  372.         goto SAGAIN;
  373.       }
  374.       }
  375.     newlex[indx] = val;    /* save value */
  376.     
  377.   }
  378.  
  379. /* ===============================>>> SYNO <<<========================*/
  380.   syno()
  381.   {
  382.  
  383.     FAST int j, i, valfrom, valto, found;
  384.     
  385. SAGAIN:
  386.     cls();
  387.     remark("You may now define up to 19 synonyms.  For example, you might");
  388.     remark("want to define a space to be a synonym for right, or RETURN");
  389.     remark("the same as down.  You must use unused values, however.  You");
  390.     remark("can't use a existing command as a synonym.  You may enter the");
  391.     remark("character followed by a RETURN, or the decimal value of the key.");
  392.  
  393.     for (i = 0 ; i < 20 ; ++i)
  394.       {
  395.     synofr[i] = synoto[i] = 0;
  396.       }
  397.  
  398.     for (i = 0 ; i < 19 ; ++i)
  399.       {
  400. SYNAGAIN:
  401.     BL;
  402.     prompt("Enter the new synonym (RETURN when done): ");
  403.     reply(rp,10);
  404.     valfrom = getval(rp);
  405.     if (valfrom == 0)
  406.         break;
  407.     for (j = 1 ; j <= LEXVALUES ; ++j)
  408.       {
  409.         if (lexsym[j] == valfrom)
  410.           {
  411.         remark("That is already a command! Try again.");
  412.         goto SYNAGAIN;
  413.           }
  414.       }
  415.     prompt("Enter the equivalent command: ");
  416.     reply(rp,10);
  417.     valto = getval(rp);
  418.     for (j = 1, found = FALSE ; j <= LEXVALUES ; ++j)
  419.       {
  420.         if (lexsym[j] == valto)
  421.             found = TRUE;
  422.       }
  423.     if (!found)
  424.       {
  425.         remark("That is not a defined command. Try again.");
  426.         goto SYNAGAIN;
  427.       }
  428.  
  429.     synofr[i] = valfrom;
  430.     synoto[i] = valto;
  431.       }
  432.     cls();
  433.  
  434. remark("Synonyms have been defined. You can start over if you made any mistakes.");
  435.     remark("");
  436.     prompt("Are they ok? (y/n) ");
  437.     lreply(rp,10);
  438.     if (*rp == 'n')
  439.     goto SAGAIN;
  440.  
  441.     for (i = 0 ; i < 20 ; ++i)
  442.         fputc(synofr[i],f);
  443.     for (i = 0 ; i < 20 ; ++i)
  444.         fputc(synoto[i],f);
  445.  
  446.   }
  447.  
  448. /* ===============================>>> CLS <<<========================*/
  449.   cls()
  450.   {
  451.     FAST int i;
  452.     for (i = 0 ; i < 25 ; ++i)
  453.     remark("");
  454.   }
  455.  
  456. #define EXTENDED    /* my own extended lib functions */
  457. /* #define STANDARD    /* the set of standard functions i use */
  458. #define LOCAL static    /* make all local globals, i think */
  459.  
  460. #ifdef EXTENDED
  461. /*=============================>>> CLOWER  <<<================================*/
  462.   char clower(ch)
  463.   char ch;
  464.   {
  465.     return ((ch >='A' && ch<='Z') ? ch + ' ' : ch);
  466.   }
  467.  
  468. /*=============================>>> CUPPER  <<<================================*/
  469.   char cupper(ch)
  470.   char ch;
  471.   {
  472.     return ((ch >= 'a' && ch <= 'z') ? ch - ' ' : ch);
  473.   }
  474.  
  475. /* =========================>>> LOWER  <<<==============================*/
  476.   lower(str)
  477.   char str[];
  478.   {
  479.     FAST int i;
  480.  
  481.     for (i=0 ; str[i] ; ++i)
  482.     str[i]=clower(str[i]);
  483.  
  484.   }
  485.  
  486. /*=============================>>> PROMPT <<<================================*/
  487.   prompt(msg)
  488.   char msg[];
  489.   {
  490.     printf("%s",msg);
  491.   }
  492.  
  493.  
  494. /*=============================>>> REMARK <<<================================*/
  495.   remark(msg)
  496.   char msg[];
  497.   {
  498.     printf("%s\n",msg);
  499.   }
  500.  
  501. /*=============================>>> UPPER  <<<================================*/
  502.   upper(str)
  503.   char str[];
  504.   {
  505.     static int i;
  506.  
  507.     for (i=0 ; str[i] ; ++i)
  508.     str[i]=cupper(str[i]);
  509.   }
  510.  
  511.  
  512. /*=============================>>> LREPLY <<<================================*/
  513.   lreply(msg,maxc)
  514.   char msg[];
  515.   int maxc;
  516.   {
  517.     reply(msg,maxc);
  518.     lower(msg);
  519.   }
  520.  
  521. /*=============================>>> UREPLY <<<================================*/
  522.   ureply(msg,maxc)
  523.   char msg[];
  524.   int maxc;
  525.   {
  526.     reply(msg,maxc);
  527.     upper(msg);
  528.   }
  529.  
  530. /*=============================>>> REPLY <<<================================*/
  531.   reply(msg,maxc)
  532.   char msg[];
  533.   int maxc;
  534.   {
  535. #ifdef UNIX
  536.     gets(msg);
  537. #else
  538.     ms_reply(msg,maxc);
  539. #endif
  540.   }
  541.  
  542. /*=============================>>> RDINT <<<================================*/
  543.   rdint(val)
  544.   int *val;
  545.   {
  546.     char chrrep[12];
  547.     reply(chrrep,11);
  548.     *val = atoi(chrrep);
  549.   }
  550. #endif
  551. #ifdef MSDOS
  552. /*=============================>>> MS_REPLY <<<================================*/
  553.   ms_reply(msg,maxc)
  554.   char msg[];
  555.   int maxc;
  556.   {
  557. #define CBS 8        /* Backspace */
  558. #define CDL1 21        /* ^U */
  559. #define CDL2 24        /* ^X */
  560. #define CABORT 3    /* ^C */
  561. #define CRET 13        /* cr */
  562. #define BACKSPACE 8
  563.  
  564.     static char ch, rp;
  565.     static int i;
  566.  
  567.  
  568.     for (i = 0 ; i < maxc ; )    /* i -> next char */
  569.       {
  570.     ch = bdos(7,-1) & 0377;     /* read the character */
  571.     if (ch == CBS)        /* back space */
  572.       {
  573.         if (i > 0)        /* must be something to delete */
  574.           {
  575.         --i;        /* wipe out char */
  576.         bdos(2,BACKSPACE); bdos(2,' '); bdos(2,BACKSPACE);
  577.         if (msg[i] < ' ')    /* double echo ^ chrs */
  578.           {
  579.             bdos(2,BACKSPACE); bdos(2,' '); bdos(2,BACKSPACE);
  580.           }
  581.           }
  582.       }
  583. #ifdef USE_WIPE
  584.     else if (ch == CDL1 || ch == CDL2)    /* wipe whole line */
  585.       {
  586.         i = 0;        /* set for loop ++ */
  587.         remark("#");
  588.         prompt("Re-enter? ");
  589.       }
  590. #endif
  591.     else if (ch == CABORT)
  592.       {
  593.         remark("^C");
  594.         prompt("Exit to operating system - are you sure? (y/n) ");
  595.         rp = bdos(7,-1) & 0377;
  596.         if (rp == 'y' || rp =='Y')
  597.          {
  598.         remark("y");
  599.         exit(0);
  600.          }
  601.         remark("n");
  602.         msg[i] = 0;
  603.         prompt("Re-enter? "); prompt(msg);        /* re-echo */
  604.       }
  605.     else if (ch == CRET)        /* ret, so done */
  606.       {
  607.         remark("");
  608.         msg[i] = 0;
  609.         return;
  610.       }
  611.     else
  612.       {
  613.         msg[i++] = ch;
  614.         msg[i] = 0;            /* always 0 terminate */
  615.         if (ch < ' ')
  616.           {
  617.         ch += '@';
  618.         bdos(2,'^');
  619.           }
  620.         bdos(2,ch);            /* echo char */
  621.       }
  622.       } /* end for */
  623.  
  624.     remark("");
  625.   }
  626.  
  627. #endif
  628. /* ------------------------------- tvx_cfg.c ------------------------ */
  629.